<?php
/**
 * Created by PhpStorm.
 * User: lcz
 * Date: 2018/3/13
 * Time: 17:24
 * 充值控制器
 */
namespace app\api\controller;

use app\api\model\LogPhoneMoneyModel;
use app\api\model\LogVoucherMoneyModel;
use app\api\model\RechargeLogModel;
use app\api\model\User;
use app\common\controller\Api;
use app\common\controller\Wxpay;
use app\common\model\CardList;
use app\common\model\FundsRecord;
use app\common\model\RechargeLog;
use app\common\model\RechargePackage;
use think\Db;
use think\Exception;
use AopClient;

class Recharge extends Api{
	
	protected $noNeedRight = ['*'];
	protected $noNeedLogin = ['alinotify', 'wxnotify'];
	
	
	/**
	 * 获取充值套餐
	 */
	public function getPackage(){
		$time = time();
		$where = [
			'ai.position' => 13,
			'ai.begin_time' => ['elt', $time],
			'ai.end_time' => ['egt', $time],
		];
		
		//顶部轮播图
		$indexAds = Db::name('appIndex')->alias('ai')
			->join('appClass ac', 'ai.app_class_id = ac.id', 'left')
			->where($where)
			->field('ai.position, ai.app_image, ai.name, ai.url, ai.param_id, ai.login, ac.ios_class, ac.android_class')
			->order(['ai.sort' => 'ASC'])
			->select();
		$returnData['banner'] = $indexAds;
		
		$model = new RechargePackage();
		
		//充值类型
		$types = RechargePackage::$_type;
		$payType = RechargePackage::$_pay_type;
		foreach ($types as $k => $v) {
			$returnData['types'][$k] = [
				'type' => $k,
				'name' => $v,
				'input' => 0,
				'package' => [],
				'packages' => [],
			];
			
			$where = [
				'type' => $k,
				'status' => $model::STATUS_Y,
			];
			$package = Db::name('RechargePackage')->where($where)->select();
			if($package) {
				foreach($package as $key => $value){
					$pay = $value['pay_type'] == $model::TYPE_5 ? '元' : $payType[$value['pay_type']];
					$data = [
						'id' => $value['id'],
						'package_id' => $value['id'],
						'content' => $value['amount'].' '.$types[$value['type']],
						'pay_content' => $value['pay_amount'].' '.$pay,
						'time_content' => '有效期'.$value['days'].'天',
						'desc' => $value['content']
					];
					$returnData['types'][$k]['package'][] = $data;
					$returnData['types'][$k]['packages'][] = $data;
				}
			}
		}
		
		$returnData['types'] = array_values($returnData['types']);
		$this->success('查询成功', $returnData);
	}
	
	/**
	 * 充值
	 */
	public function recharge(){
		//套餐ID
		$packageId = input('post.package_id','','int');
		//用户ID
		$userId = $this->auth->id;
		
		//充值类型
		$type = input('post.type','', 'int');
		
		
		//充值金额
		$amount = input('post.amount','','float');
		
		//充值手机号
		$phone = input('post.phone');
		!$phone && $this->error('请输入要充值的手机号码');
		
		
		if(!$type){
			$this->error('请选择充值类型');
		}
		
		$packageModel = new RechargePackage();
		$pay_type = $packageModel::$_pay_type;
		$rechargeType = $packageModel::$_type;
		
		$remark = '';
		
		$user = Db::name('user')->find($userId);
		
		$targetUser = Db::name('user')
			->where(['mobile' => $phone])
			->find();
		!$targetUser && $this->error('充值号码绑定用户不存在');
		
		//要充值的目标会员ID
		$targetUserId = $targetUser['id'];
		
		$payType = '';
		
		if(!$packageId){
			//自己输入金额的充值
			if(!$amount || $amount < 1) {
				$this->error('最少充值1元');
			}
			
			$payAmount = $amount;
		} else {
			// 套餐的充值
			$package = $packageModel
				->where([
					'id' => $packageId,
					'type' => $type,
					'status' => $packageModel::STATUS_Y
				])->find();
			
			if(!$package){
				$this->error('充值套餐不存在');
			}
			
			$amount = $package['amount'];
			if($package['pay_type'] != $packageModel::TYPE_5) {
				$payType = $package['pay_type'];
				$remark = '使用'.$pay_type[$package['pay_type']].'充值'.$rechargeType[$package['type']];
			}
			
			$payAmount = $package['pay_amount'];
		}
		
		$orderNo = $userId.time();
//		$payAmount = 0.1;
		//充值记录数据
		$logData = [
			'user_id' => $userId,
			'order_no' => $orderNo,
			'amount' => $amount,
			'pay_type' => $payType,
			'create_time' => time(),
			'pay_amount' => $payAmount,
			'status' => RechargeLog::STATUS_W,
			'type' => $type,
			'remark' => $remark,
			'days' => isset($package['days'])?$package['days']:0,
			'recharge_user_id' => $targetUserId,
			'gift_integral' => $package ? $package['gift_integral'] : 0,
			'gift_voucher' => $package ? $package['gift_voucher'] : 0,
		];
		
		$logModel = new RechargeLog();
		Db::startTrans();
		$fields = $packageModel::$_fields;
		try {
			//添加充值记录
			$logId = $logModel->insertGetId($logData);
			if(!$logId) {
				throw new Exception('创建充值订单出错，请稍候重试');
			}
			
			//如果不是在线支付，扣除对应的钱包金额，给对应的钱包金额添加金额
			//如果有套餐ID，但是套餐的付款方式不是在线支付，那么就是钱包相互转帐
			if($packageId && $package['pay_type'] != $packageModel::TYPE_5){
				if($user[$fields[$payType]] < $payAmount) {
					throw new Exception($pay_type[$payType].'余额不足,当前余额：'.$user[$fields[$payType]]);
				}
				
				$newData = [
					$fields[$payType] => $user[$fields[$payType]] - $payAmount,
				];
				
				$targetData = [
					$fields[$type] => $user[$fields[$type]] + $amount,
				];
				
				//如果是充值话费，添加有效期
				if($package['type'] == $packageModel::TYPE_2){
					$time = time();
					if($user['phone_time']>$time){
						$time = $user['phone_time'];
					}
					
					$targetData['phone_time'] = $time+$package['days']*24*3600;
				}
				
				//减少支付类型的金额
				$res = Db::name('user')->where(['id' => $userId])->update($newData);
				if(!$res){
					throw new Exception('减少帐户资金出错');
				}
				
				$fundsModel = new FundsRecord();
				//套餐有赠送优惠券
				if($package['gift_integral'] > 0) {
					if($fields[$type] == 'integral') {
						$targetData['integral'] = $targetData['integral'] + $package['gift_integral'];
					} else {
						$targetData['integral'] = $user['integral'] + $package['gift_integral'];
					}
					
					$rechargeRes = $fundsModel->addRecord($targetUser['id'], $package['gift_integral'], $targetData['integral'],FundsRecord::ACCOUNT_TYPE_INTEGRAL, $fundsModel::OPE_TYPE_PLUS, $fundsModel::TYPE_RECHARGE, '', '充值套餐赠送');
					if(!$rechargeRes) {
						throw new Exception('添加充值流水记录出错');
					}
				}
				
				//套餐有赠送优惠券
				if($package['gift_voucher'] > 0) {
					if($fields[$type] == 'voucher_balance') {
						$targetData['voucher_balance'] = $targetData['voucher_balance'] + $package['gift_voucher'];
					} else {
						$targetData['voucher_balance'] = $user['voucher_balance'] + $package['gift_voucher'];
					}
					
					$rechargeRes = $fundsModel->addRecord($targetUser['id'], $package['gift_voucher'], $targetData['voucher_balance'],FundsRecord::ACCOUNT_TYPE_VOUCHER, $fundsModel::OPE_TYPE_PLUS, $fundsModel::TYPE_RECHARGE, '', '充值套餐赠送');
					if(!$rechargeRes) {
						throw new Exception('添加充值流水记录出错');
					}
				}
				
				//添加充值类型的金额
				$targetRes = Db::name('user')->where(['id' => $targetUserId])->update($targetData);
				if(!$targetRes){
					throw new Exception('添加帐户资金出错');
				}
				$_account_type = $fundsModel::$_account_type;
				
				//添加充值流水
				$rechargeRes = $fundsModel->addRecord($targetUser['id'], $amount, $targetUser[$fields[$type]],$type, $fundsModel::OPE_TYPE_PLUS, $fundsModel::TYPE_RECHARGE, '', '使用'.$_account_type[$payType].'充值'.$_account_type[$type]);
				if(!$rechargeRes) {
					throw new Exception('添加充值流水记录出错');
				}
				
				//添加付款流水
				$payRes = $fundsModel->addRecord($userId, $payAmount, $user[$fields[$payType]],$payType, $fundsModel::OPE_TYPE_LESS, $fundsModel::TYPE_PAY_RECHARGE, '', '使用'.$_account_type[$payType].'充值'.$_account_type[$type]);
				if(!$payRes) {
					throw new Exception('添加付款流水记录出错');
				}
				
				
				//更改充值订单状态
				$logRes = Db::name('rechargeLog')->where(['id' => $logId])->update(['pay_time' => time(), 'status' => $logModel::STATUS_Y]);
				if(!$logRes){
					throw new Exception('更改充值记录状态出错');
				}
				
				
				Db::commit();
				$this->success('充值成功');
				
			} else {
				Db::commit();
				//如果是在线支付，判断是支付宝还是微信支付，返回对应的支付参数
				$this->success('生成订单成功',['order_id' => $logId], 201);
			}
			
			
		} catch (Exception $e){
			Db::rollback();
			$this->error($e->getMessage());
		}
	}
	
	/**
	 * 在线支付订单请求支付宝或微信支付参数
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	public function payRechargeOrder(){
		$user_id = $this->auth->id;
		$payment_id = input('post.payment_id');
		$order_id = input('post.order_id');
		
		if (!$user_id || !$payment_id || !$order_id) {
			$this->showResponse(400,'','参数错误')->finished();
		}
		//判断用户余额和积分
		$userinfo = Db::name('user')->find($user_id);
		
		$order = Db::name('rechargeLog')->find($order_id);
		if(!$order){
			$this->error('订单不存在');
		}
		
		if($order['status'] != RechargeLog::STATUS_W){
			$this->error('非待支付充值订单');
		}
		
		$paymentModel = new \app\common\model\Payment();
		//查找支付方式
		$payment = $paymentModel
			->where([
				'status' => $paymentModel::STATUS_Y,
				'id' => $payment_id,
			])
			->find();
		!$payment && $this->error('支付方式错误');
		
		switch ($payment['pay_type']) {
			//支付宝
			case $paymentModel::PAY_TYPE_ALI:
				$returnArr['orderid'] = $order['order_no'];
				$returnArr['callback'] = $this->request->domain() . url('api/recharge/aliNotify','','');
				$returnArr['acctId'] = $payment['appid'];
				$returnArr['sellerId'] = $payment['appid'];
				$returnArr['privatekey'] = $payment['private_key'];
				$returnArr['keyWord'] = 'recharge';
				$returnArr['amount'] = $order['pay_amount'];
				
				$this->success("OK",$returnArr);
				break;
			case $paymentModel::PAY_TYPE_WEIXIN:
				//微信支付
				$config = [
					'appid' => $payment['appid'],
					'mch_id' => $payment['mch_id'],
					'mch_key' => $payment['private_key'],
				];
				
				$wxPay = load_wec("Pay",$config);
				$callback = $this->request->domain() . url('api/recharge/wxNotify','','');
				$data = [
					"body"              => 'Pay',
					"out_trade_no"      => (string)$order['order_no'],
					'attach'            => 'payorder', //附加数据(非必填)
					"total_fee"         => $order['pay_amount'] *100,
					"notify_url"        => $callback,
					"trade_type"        => 'APP',
					"fee_type"          => 'CNY',
					"spbill_create_ip"  => $this->request->ip()
				];
				
				$res = $wxPay->createOrder($data);
				$prepay_id = $res['prepay_id'];
				$result = $wxPay->createMchPay($prepay_id);
				$returnArr = [
					'keyWord' => 'pay_recharge',
					'acctId' => $payment['mch_id'],
					'orderid' => $order['order_no'],
					'callback' => $callback,
					"sign" => $result['paySign'],
					"sellerId" => $payment['mch_id'],
					"prepay_id" => $prepay_id,
					"appid" => $payment['appid'],
					"nonce_str" => $result['nonceStr'],
					"trade_type" => "APP",
					"amount" => $order['pay_amount'],
					"privateKey" => $payment['private_key']
				];
				$this->success("OK",$returnArr);
				break;
			default:
				$this->showResponse(400,'','支付方式错误','')->finished();
		}
		
	}
	
	/**
	 * 支付宝充值异步处理
	 */
	public function aliNotify(){
		header('Content-type:text/html;charset=utf8');
//		$json = '{"gmt_create":"2018-03-16 16:08:26","charset":"utf-8","seller_email":"2876978098@qq.com","subject":"\u5546\u54c1\u4ed8\u6b3e","sign":"V+YukHVMug4FnMo3+nrqVDzWkuWsIbfzm1TeBPxbwkllGoeddCKLzIP2DX+hal506wgQOtjlCdOqbXjNOEwm+X2Ln80ZNj4bFNaaADYQtSpW9IkPyYSdrySnsWRjgDzQwhPeO1YFCoXG4nJDfh+V\/x93j8TITdG1niJZn+MLehIfgOG5gujgP87tcGfrz4YQusTOOZ7Yn0Mjfp4jLOjIRfDBg92vva0xGsgV3D5AW1\/teTWyLe5ksm2BxJ2fbC1lq41zOiI+V5MWJcd3XGGuR5z9JlpFksKz6UqaFkVDrcKGkAUVj5pRMoWon5XxipGPcoLC\/\/t99X9ohOX8Uctj\/g==","body":"recharge","buyer_id":"2088712473897918","invoice_amount":"0.10","notify_id":"72707517596363df8e33ab13f425829n0x","fund_bill_list":"[{\"amount\":\"0.10\",\"fundChannel\":\"ALIPAYACCOUNT\"}]","notify_type":"trade_status_sync","trade_status":"TRADE_SUCCESS","receipt_amount":"0.10","app_id":"2016010201058673","buyer_pay_amount":"0.10","sign_type":"RSA2","seller_id":"2088011180472635","gmt_payment":"2018-03-16 16:08:27","notify_time":"2018-03-16 16:22:06","version":"1.0","out_trade_no":"sp15175656571521187699","total_amount":"0.10","trade_no":"2018031621001004910512136767","auth_app_id":"2016010201058673","buyer_logon_id":"cjs***@126.com","point_amount":"0.00"}';
//		$post = json_decode($json,true);
		
		$dir = RUNTIME_PATH.'notify/alipayRechargeLog/';
		if (!is_dir($dir)) {
			mkdir($dir, 0755, true);
		}
		$str = "\r\n==========================" . date('Y-m-d H:i:s') . "================================================================\r\n";
		$str .= "处理方式：异步处理 ！.\r\n";
		$str .= json_encode($_POST) . "\r\n";
		$str .= "==========================================================================================\r\n";
		$mytext = $dir . date('Y-m-d').'.txt';
		file_put_contents($mytext, $str . " \r\n", FILE_APPEND);
		$aop = load_ali();
		
		$pay_no = $_POST['out_trade_no'];
		$model = new RechargeLog();
		$row = $model->where(['order_no' => $pay_no])->find();
		if(!$row) {
			file_put_contents($mytext, '数据不存在'. "\r\n", FILE_APPEND);
			die();
		}
		
		$paymentModel = new \app\common\model\Payment();
		$payment = $paymentModel
			->where(['pay_type' => $paymentModel::PAY_TYPE_ALI])
			->find();
		
		$aop->alipayrsaPublicKey = $payment['public_key'];
		$flag = $aop->rsaCheckV1($_POST, null, "RSA2");
		if (!$flag) {
//			echo '验证失败<br>';
			file_put_contents($mytext, '验证失败', FILE_APPEND);
			die;
		}
        if (isset($_POST['trade_status']) && $_POST['trade_status']!='TRADE_SUCCESS' && $_POST['trade_status']!='TRADE_SUCCESS')
        {
            file_put_contents($mytext, '交易失败'. "\r\n", FILE_APPEND);
            echo 'failure';
            die();
        }
		$trade_no = $_POST['trade_no'];
		$amount = $_POST['total_amount'];
		$res = $model->paySuccess($pay_no, $amount, $trade_no, $model::TYPE_5);
		if($res){
			file_put_contents($mytext, '支付成功', FILE_APPEND);
			echo 'SUCCESS';
			die;
		} else {
			file_put_contents($mytext, $model->getError(), FILE_APPEND);
			die;
		}
	}
	
	/**
	 * 微信充值异步处理
	 */
	public function wxNotify(){
		
		header('Content-type:text/html;charset=utf8');
		$dir = '../runtime/wxpayRechargeLog/';
		if(!is_dir($dir)) {
			mkdir($dir, 0755, true);
		}
		$mytext = $dir.date('Y-m-d').'.txt';
		file_put_contents($mytext,'==================='.date('Y-m-d H:i:s')."==============\r\n", FILE_APPEND);
		
		$xml = $GLOBALS['HTTP_RAW_POST_DATA']; //返回的xml
//		//记录日志 支付成功后查看weixin.txt文件是否有内容 如果有xml格式文件说明回调成功
		$xmlObj=simplexml_load_string($xml,'SimplexmlElement',LIBXML_NOCDATA);
		file_put_contents($mytext, json_encode($xmlObj)."\r\n", FILE_APPEND);
		$data=json_decode(json_encode($xmlObj),true);

//		$json = '{"appid":"wx920fe24dbcd8e5a1","attach":"recharge","bank_type":"CFT","cash_fee":"10","fee_type":"CNY","is_subscribe":"N","mch_id":"1426475002","nonce_str":"8jzi1g5van6v7guneve9du0imfqeu9rd","openid":"oxfQKwfNaJFl856T2aE5C4rdNcro","out_trade_no":"sp15175656571521191860","result_code":"SUCCESS","return_code":"SUCCESS","sign":"4126FC68AA8A5F3DFCA5017790B0EA08","time_end":"20180316171758","total_fee":"10","trade_type":"APP","transaction_id":"4200000096201803169792260197"}';
//
//		$data = json_decode($json, true);
		$data_sign = $data['sign'];
		// sign不参与签名算法
		
		$pay_no = $data['out_trade_no'];
		$model = new RechargeLog();
		$row = $model->where(['order_no' => $pay_no])->find();
		if(!$row) {
			file_put_contents($mytext, '数据不存在'. "\r\n", FILE_APPEND);
			die();
		}
		
		$paymentModel = new \app\common\model\Payment();
		$payment = $paymentModel
			->where(['pay_type' => $paymentModel::PAY_TYPE_WEIXIN])
			->find();
		
		//微信支付
		$config = [
			'appid' => $payment['appid'],
			'mch_id' => $payment['mch_id'],
			'mch_key' => $payment['private_key'],
		];
		
		$wxPay = load_wec("Pay",$config);
		$sign = $wxPay->checkSign($data);
		
		// 判断签名是否正确  判断支付状态
		if ( !$sign || ($data['return_code']!='SUCCESS') || ($data['result_code']!='SUCCESS') ) {
//			echo '验证失败';
			file_put_contents($mytext, '验证失败', FILE_APPEND);
			die;
		}
		
		
		$trade_no = $data['transaction_id'];
		$amount = $data['total_fee']/100;
		
		$res = $model->paySuccess($pay_no, $amount, $trade_no, $model::TYPE_6);
		if($res) {
			file_put_contents($mytext, "=========支付成功=========\r\n", FILE_APPEND);
//			echo '支付成功';
			$xml = "<xml>
 <return_code><![CDATA[SUCCESS]]></return_code>
 <return_msg><![CDATA[OK]]></return_msg>
</xml>";
			echo $xml;
			die;
		} else {
			file_put_contents($mytext, '=======支付出错：'.$model->getError()."=====\r\n", FILE_APPEND);
			die;
		}
		
		
	}
	
	
	/**
	 * 卡号和密码充值
	 */
	public function cardRecharge(){
		$userId = $this->auth->id;
		$no = input('post.no');
		$password = input('post.password');
		if(!$userId || !$no || !$password) {
			$this->error('参数错误');
		}
		
		$model = new CardList();
		
		$row = $model
			->where(['no' => $no, 'password' => $password])
			->find();
		!$row && $this->error('充值卡信息不正确');
		
		
		if($row['expiration_time'] < time()) {
			$this->error('充值卡已过期');
		}
		
		if($row['status'] == $model::STATUS_N) {
			$this->error('该充值卡不可使用');
		}
		
		if($row['status'] == $model::STATUS_Y) {
			$this->error('该充值卡已在【'.date('Y-m-d H:i:s', $row['use_time']).'】使用');
		}
		
		Db::startTrans();
		try {
			
			$user = Db::name('user')->where(['id' => $userId])->find();
			if($row['type'] == $model::TYPE_PHONE) {
				//话费充值
				//更改帐户余额和有效期
				if(!$user['phone_time'] || $user['phone_time'] < time()) {
					$endTime = time()+$row['days'] * 24*3600;
				} else {
					$endTime = $user['phone_time'] + $row['days'] *24*3600;
				}
				
				$userData = [
					'phone_balance' => $user['phone_balance'] + $row['amount'],
					'phone_time' => $endTime
				];
				
				$logModel = new FundsRecord();
				$logRes = $logModel->addRecord($userId, $row['amount'], $user['phone_balance'], $logModel::ACCOUNT_TYPE_PHONE, $logModel::OPE_TYPE_PLUS, $logModel::TYPE_CARD_RECHARGE,'','充值卡充值');
				
			} else if($row['type'] == $model::TYPE_VOUCHER) {
				//优惠券充值
				$userData = [
					'voucher_balance' => $user['voucher_balance'] + $row['amount']
				];
				
				$logModel = new FundsRecord();
				$logRes = $logModel->addRecord($userId, $row['amount'], $user['voucher_balance'],
					$logModel::ACCOUNT_TYPE_VOUCHER, $logModel::OPE_TYPE_PLUS, $logModel::TYPE_CARD_RECHARGE, '',
					'充值卡充值');
			} else if($row['type'] == $model::TYPE_POINT){
				$userData = [
					'integral' => $user['integral'] + $row['amount']
				];
				
				$logModel = new FundsRecord();
				$logRes = $logModel->addRecord($userId, $row['amount'], $user['integral'],
					$logModel::ACCOUNT_TYPE_INTEGRAL, $logModel::OPE_TYPE_PLUS, $logModel::TYPE_CARD_RECHARGE, '',
					'充值卡充值');
			} else if($row['type'] == $model::TYPE_VIDEO){
                $beforeDays = 0;
				if ($user['video_time'] > time()) {
                    $beforeDays = ceil(($user['video_time']-time())/(24*60*60));
                }
                if ($beforeDays == 0) {
                    $endTime = time()+$row['days'] * 24*3600;
                }
                else
                {
                    $endTime = $user['video_time'] + $row['days'] *24*3600;
                }
                $userData = [
                    'video_time' => strtotime(date("Y-m-d 23:59:59",$endTime))
                ];
				$logModel = new FundsRecord();
				$logRes = $logModel->addRecord($userId, $row['days'], $beforeDays,
					$logModel::ACCOUNT_TYPE_VIDEO, $logModel::OPE_TYPE_PLUS, $logModel::TYPE_CARD_RECHARGE, '',
					'充值卡充值');
			} else {
				$logRes = false;
			}
			
			if(!$logRes) {
				throw new Exception('添加充值记录出错');
			}
			
			//如果没有推荐人，更改推荐人为卡的归属代理
			if(!$user['recommend_id'] && $row['agent_user_id']) {
				//更改归属代理推荐人数
				$countRes = Db::name('user')
					->where(['id' => $row['agent_user_id']])
					->setInc('recommend_count');
				
				if(!$countRes) {
					throw new Exception('统计推荐人数量出错');
				}
				//更改用户推荐人
				$userData['recommend_id'] = $row['agent_user_id'];
				$userData['parent_path'] = $row['parent_path'] ? $row['parent_path'].','.$row['agent_user_id']:$row['agent_user_id'];
				
				
			}
			
			//如果没有归属代理，更改归属代理为卡的归属代理
			if(!$user['agent_user_id'] && $row['agent_user_id']) {
				$userData['agent_user_id'] = $row['agent_user_id'];
			}
			
			$useRes = Db::name('user')
				->where(['id' => $user['id']])
				->update($userData);
			if(!$useRes) {
				throw new Exception('更改用户资金出错');
			}
			
			$res = Db::name('cardList')
				->where(['id' => $row['id']])
				->update([
					'use_time' => time(),
					'user_id' => $userId,
					'status' => $model::STATUS_Y,
				]);
			if(!$res) {
				throw new Exception('更改充值卡状态出错');
			}
			
			
			
			
			Db::commit();
			$this->success('充值成功');
			
		} catch (Exception $e) {
			Db::rollback();
			$this->error($e->getMessage());
		}
		
	}
}
